from django.db import models


# Create your models here.
class Account(models.Model):
    """账户表"""
    username = models.CharField(verbose_name='用户名', max_length=16, db_index=True)  # 为username在数据库中创建索引 db_index=True
    email = models.EmailField(verbose_name='邮箱', max_length=32)
    phone = models.CharField(verbose_name='电话', max_length=16, db_index=True)
    password = models.CharField(verbose_name='密码', max_length=64)


class PricePolicy(models.Model):
    """价格策略表"""
    category_choice = (
        (0, '免费版'),
        (1, '收费版'),
        (2, '其他'),
    )
    category = models.SmallIntegerField(verbose_name='分类', default=1, choices=category_choice)
    title = models.CharField(verbose_name='标题', max_length=64)
    price = models.PositiveIntegerField(verbose_name='价格/年')
    project_num = models.PositiveIntegerField(verbose_name='创建项目个数')
    project_member = models.PositiveIntegerField(verbose_name='每项目成员数')
    project_space = models.PositiveIntegerField(verbose_name='每个项目空间')
    per_file_size = models.PositiveIntegerField(verbose_name='单文件最大限制')
    create_datetime = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)


class Transaction(models.Model):
    """交易表"""
    status_choice = (
        (0, '未支付'),
        (1, '已支付'),
    )
    status = models.SmallIntegerField(verbose_name='状态', choices=status_choice)
    order = models.CharField(verbose_name='订单号', max_length=64, unique=True)
    user = models.ForeignKey(verbose_name='用户', to='Account')
    price_policy = models.ForeignKey(verbose_name='价格策略', to='PricePolicy')
    price = models.IntegerField(verbose_name='实际支付价格')
    count = models.IntegerField(verbose_name='数量(年）', help_text='0表示无限期')
    start_datetime = models.DateTimeField(verbose_name='开始时间', null=True, blank=True)
    end_datetime = models.DateTimeField(verbose_name='结束时间', null=True, blank=True)
    create_datetime = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)


class Project(models.Model):
    """项目表"""
    COLOR_CHOICES = (
        (0, "#56b8eb"),  # 56b8eb
        (1, "#f28033"),  # f28033
        (2, "#ebc656"),  # ebc656
        (3, "#a2d148"),  # a2d148
        (4, "#20BFA4"),  # #20BFA4
        (5, "#7461c2"),  # 7461c2,
        (6, "#20bfa3"),  # 20bfa3,
    )
    name = models.CharField(verbose_name='项目名称', max_length=32)
    desc = models.CharField(verbose_name='描述', max_length=255, null=True, blank=True)
    color = models.SmallIntegerField(verbose_name='颜色', choices=COLOR_CHOICES, default=0)
    star = models.BooleanField(verbose_name='星标', default=False)
    join_count = models.SmallIntegerField(verbose_name='参与人数', default=1)
    creator = models.ForeignKey(verbose_name='创建者', to='Account')
    use_space = models.IntegerField(verbose_name='已使用空间', default=0)
    create_datetime = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)


class ProjectUser(models.Model):
    """项目参与者"""
    project = models.ForeignKey(verbose_name='项目', to='Project')
    user = models.ForeignKey(verbose_name='参与者', to='Account')
    star = models.BooleanField(verbose_name='星标', default=False)
    create_datetime = models.DateTimeField(verbose_name='加入时间', auto_now_add=True)
